<template>
  <el-dialog
    :model-value="visible"
    @update:model-value="handleVisibleChange"
    :title="currentTask.taskId ? (currentTask.status === '2' ? '查看任务' : '编辑任务') : '新增任务'"
    width="90%"
    :close-on-click-modal="false"
    @close="handleClose"
    class="task-dialog"
  >
    <div style="display: flex; gap: 80px; height: 83vh; overflow: hidden">
      <div style="width: 70%; height: 100%; display: flex; flex-direction: column; overflow: hidden">
        <el-form :model="editTaskForm" :rules="rules" ref="formRef" label-width="100px" class="task-form">
          <!-- 任务名称 -->
          <el-form-item label="任务名称" prop="taskName">
            <el-input v-model="editTaskForm.taskName" placeholder="请输入任务名称" :disabled="currentTask.status === '2'" />
          </el-form-item>

          <!-- 发送时间 -->
          <el-form-item label="发送时间" prop="sendTimeType">
            <div class="material-section">
              <div class="material-options">
                <el-radio-group v-model="editTaskForm.sendTimeType" :disabled="currentTask.status === '2'">
                  <el-radio label="1">立即发送</el-radio>
                  <el-radio label="2">定时发送</el-radio>
                </el-radio-group>
                <el-date-picker
                  v-if="editTaskForm.sendTimeType === '2'"
                  v-model="editTaskForm.sendTime"
                  type="datetime"
                  placeholder="选择发送时间"
                  :disabled="currentTask.status === '2'"
                  prop="sendTime"
                />
              </div>
            </div>
          </el-form-item>

          <!-- 发送对象 -->
          <el-form-item label="发送对象" prop="selectedFriends">
            <div class="target-section">
              <div class="target-actions" v-if="currentTask.status !== '2'">
                <el-button type="primary" @click="handleSelectFriends">选择好友</el-button>
                <el-button type="primary" @click="handleSelectGroups">选择群组</el-button>
              </div>
              <div class="target-preview" v-if="editTaskForm.selectedFriends.length || editTaskForm.selectedGroups.length">
                <div class="target-group" v-if="editTaskForm.selectedFriends.length">
                  <div class="target-label">已选好友：</div>
                  <div class="target-list">
                    <el-tag
                      v-for="friend in editTaskForm.selectedFriends"
                      :key="friend.wxId"
                      :closable="currentTask.status !== '2'"
                      @close="handleRemoveFriend(friend)"
                      class="target-item"
                      :class="{ 'is-disabled': currentTask.status === '2' }"
                    >
                      {{ friend.wxName }}
                    </el-tag>
                  </div>
                </div>
                <div class="target-group" v-if="editTaskForm.selectedGroups.length">
                  <div class="target-label">已选群组：</div>
                  <div class="target-list">
                    <el-tag
                      v-for="group in editTaskForm.selectedGroups"
                      :key="group.groupId"
                      :closable="currentTask.status !== '2'"
                      @close="handleRemoveGroup(group)"
                      class="target-item"
                      :class="{ 'is-disabled': currentTask.status === '2' }"
                    >
                      {{ group.groupName }}
                    </el-tag>
                  </div>
                </div>
              </div>
            </div>
          </el-form-item>
        </el-form>

        <div class="selectSend">
          <div class="section-title">内容类型</div>
          <el-tabs :model-value="activeMessageType" @update:model-value="handleMessageTypeChange" class="message-tabs" :disabled="currentTask.status === '2'">
            <el-tab-pane label="文本" name="text">
              <el-form-item label="文本内容">
                <el-input
                  v-model="currentMessage.data.content"
                  type="textarea"
                  :rows="4"
                  placeholder="请输入文本内容"
                  :disabled="currentTask.status === '2'"
                  maxlength="2000"
                  show-word-limit
                />
              </el-form-item>
            </el-tab-pane>
            <el-tab-pane label="图片" name="image">
              <el-form-item label="图片上传">
                <el-upload
                  list-type="picture-card"
                  action="#"
                  :auto-upload="false"
                  :on-change="handleImageChange"
                  :on-remove="handleRemoveImage"
                  :on-preview="handlePreviewImage"
                  :file-list="currentMessage.data.imageUrl ? [{ name: '图片', url: currentMessage.data.imageUrl }] : []"
                  :disabled="currentTask.status === '2'"
                >
                  <el-icon><Plus /></el-icon>
                </el-upload>
              </el-form-item>
            </el-tab-pane>
            <el-tab-pane label="视频" name="video">
              <el-form-item label="视频上传">
                <el-upload
                  class="video-uploader"
                  action="#"
                  :auto-upload="false"
                  :show-file-list="false"
                  :on-change="handleVideoChange"
                  :disabled="currentTask.status === '2'"
                >
                  <video v-if="currentMessage.data.videoUrl" :src="currentMessage.data.videoUrl" class="preview-video" controls />
                  <el-icon v-else class="upload-icon"><Plus /></el-icon>
                </el-upload>
              </el-form-item>
            </el-tab-pane>
            <!-- <el-tab-pane label="链接" name="link">
              <el-form-item label="链接地址">
                <el-input v-model="currentMessage.data.url" placeholder="请输入链接地址" :disabled="currentTask.status === '2'" />
              </el-form-item>
              <el-form-item label="链接标题">
                <el-input v-model="currentMessage.data.title" placeholder="请输入链接标题" :disabled="currentTask.status === '2'" />
              </el-form-item>
            </el-tab-pane> -->
          </el-tabs>

          <div class="message-actions" v-if="currentTask.status !== '2'">
            <el-button type="primary" @click="handleAddMessage">添加单条</el-button>
          </div>

          <div class="message-preview-item-list">
            <div class="preview-title" v-if="messageList.length > 0">已添加消息列表</div>
            <div class="message-preview-item-list">
              <el-card v-for="(message, index) in messageList" :key="index" class="message-preview-item">
                <div class="preview-header">
                  <div class="message-info">
                    <span class="message-type-tag" :class="message.type">{{ getMessageTypeLabel(message.type) }}</span>
                    <div class="message-content">
                      <template v-if="message.type === 'text'">
                        {{ message.data.content }}
                      </template>
                      <template v-else-if="message.type === 'image'">
                        <img :src="message.data.imageUrl" class="preview-image" />
                      </template>
                      <template v-else-if="message.type === 'video'">
                        <video :src="message.data.videoUrl" class="preview-video" controls />
                      </template>
                      <template v-else-if="message.type === 'link'">
                        <div class="link-preview">
                          <div class="link-title">{{ message.data.title }}</div>
                          <div class="link-url">{{ message.data.url }}</div>
                        </div>
                      </template>
                    </div>
                  </div>
                  <div class="preview-actions" v-if="currentTask.status !== '2'">
                    <div class="action-buttons">
                      <el-button type="primary" link :disabled="index === 0" @click="handleMoveMessage(index, 'up')"> </el-button>
                      <el-button type="primary" link :disabled="index === messageList.length - 1" @click="handleMoveMessage(index, 'down')"> </el-button>
                      <el-button type="danger" link @click="handleDeleteMessage(index)"> </el-button>
                    </div>
                  </div>
                </div>
              </el-card>
            </div>
          </div>
        </div>
      </div>

      <div class="right-content">
        <div class="right-content-preview">
          <div class="wechat-preview">
            <div class="wechat-header">
              <div class="wechat-title">用户消息预览</div>
            </div>
            <div class="wechat-messages" ref="messageContainer">
              <template v-for="(message, _index) in messageList" :key="_index">
                <div class="message-item" :class="message.type">
                  <div class="message-avatar">
                    <img src="@/assets/avatar.jpg" alt="avatar" />
                  </div>
                  <div class="message-content">
                    <div class="message-bubble">
                      <template v-if="message.type === 'text'">
                        {{ message.data.content }}
                      </template>
                      <template v-else-if="message.type === 'image'">
                        <img :src="message.data.imageUrl" class="preview-image" />
                      </template>
                      <template v-else-if="message.type === 'video'">
                        <video :src="message.data.videoUrl" class="preview-video" controls />
                      </template>
                      <template v-else-if="message.type === 'link'">
                        <div class="link-preview">
                          <div class="link-title">{{ message.data.title }}</div>
                          <div class="link-url">{{ message.data.url }}</div>
                        </div>
                      </template>
                    </div>
                  </div>
                </div>
              </template>
            </div>
          </div>
        </div>
      </div>
    </div>

    <template #footer>
      <span class="dialog-footer">
        <el-button @click="handleClose">{{ currentTask.status === '2' ? '关闭' : '取消' }}</el-button>
        <el-button type="primary" @click="handleSubmit" v-if="currentTask.status !== '2'">确定</el-button>
      </span>
    </template>

    <!-- 选择好友对话框 -->
    <FriendSelectDialog
      v-model:visible="selectFriendsDialogVisible"
      :selected="editTaskForm.selectedFriends"
      @confirm="handleFriendSelectConfirm"
      :multiple="true"
      @cancel="selectFriendsDialogVisible = false"
    />

    <!-- 选择群组对话框 -->
    <GroupSelectDialog
      v-model:visible="selectGroupsDialogVisible"
      :selected="editTaskForm.selectedGroups"
      @confirm="handleGroupSelectConfirm"
      :multiple="true"
      @cancel="selectGroupsDialogVisible = false"
    />
  </el-dialog>
</template>

<script setup lang="ts">
import { ref, watch } from 'vue';
import { Plus, ArrowUp, ArrowDown, Delete } from '@element-plus/icons-vue';
import { ElMessage } from 'element-plus';
import FriendSelectDialog from '@/components/FriendSelect/FriendSelectDialog.vue';
import GroupSelectDialog from '@/components/GroupSelect/GroupSelectDialog.vue';
import type { FormInstance } from 'element-plus';

// 定义类型
type MessageType = 'text' | 'image' | 'video' | 'link';

interface Friend {
  wxId: string;
  wxName: string;
}

interface Group {
  groupId: string;
  groupName: string;
}

interface MessageData {
  type: MessageType;
  data: {
    content?: string;
    imageUrl?: string;
    videoUrl?: string;
    url?: string;
    title?: string;
  };
}

interface TaskForm {
  taskName: string;
  sendTimeType: '1' | '2';
  sendTime?: string;
  selectedFriends: Friend[];
  selectedGroups: Group[];
}

interface PrecisionMessagingTask {
  taskId?: string;
  status: string;
  taskName?: string;
  sendTimeType?: '1' | '2';
  sendTime?: string;
  selectedFriends?: Friend[];
  selectedGroups?: Group[];
}

interface Props {
  visible: boolean;
  currentTask: PrecisionMessagingTask;
  editTaskForm: TaskForm;
  messageList: MessageData[];
  currentMessage: MessageData;
  activeMessageType: MessageType;
  messageContainer: HTMLElement | null;
}

const props = defineProps<Props>();

const emit = defineEmits<{
  (e: 'update:visible', value: boolean): void;
  (e: 'update:currentMessage', value: MessageData): void;
  (e: 'update:editTaskForm', value: TaskForm): void;
  (e: 'update:messageList', value: MessageData[]): void;
  (e: 'update:activeMessageType', value: MessageType): void;
  (e: 'close'): void;
  (e: 'submit'): void;
  (e: 'image-change', file: File): void;
  (e: 'video-change', file: File): void;
  (e: 'add-message', value: MessageData): void;
}>();

// 选择好友和群组对话框的显示状态
const selectFriendsDialogVisible = ref(false);
const selectGroupsDialogVisible = ref(false);

// 表单验证规则
const rules = {
  taskName: [
    { required: true, message: '请输入任务名称', trigger: 'blur' },
    { min: 2, max: 50, message: '长度在 2 到 50 个字符', trigger: 'blur' }
  ],
  sendTimeType: [{ required: true, message: '请选择发送时间类型', trigger: 'change' }],
  sendTime: [{ required: true, message: '请选择发送时间', trigger: 'change' }],
  selectedFriends: [{ type: 'array', required: true, message: '请选择发送对象', trigger: 'change' }]
};

const formRef = ref<FormInstance>();

// 获取消息类型标签
const getMessageTypeLabel = (type: MessageType): string => {
  const typeMap: Record<MessageType, string> = {
    text: '文本',
    image: '图片',
    video: '视频',
    link: '链接'
  };
  return typeMap[type] || type;
};

// 处理消息移动
const handleMoveMessage = (index: number, direction: 'up' | 'down') => {
  const newIndex = direction === 'up' ? index - 1 : index + 1;
  if (newIndex >= 0 && newIndex < props.messageList.length) {
    const newMessageList = [...props.messageList];
    const [movedMessage] = newMessageList.splice(index, 1);
    newMessageList.splice(newIndex, 0, movedMessage);
    emit('update:messageList', newMessageList);
  }
};

// 处理消息删除
const handleDeleteMessage = (index: number) => {
  const newMessageList = [...props.messageList];
  newMessageList.splice(index, 1);
  emit('update:messageList', newMessageList);
};

// 处理对话框可见性变化
const handleVisibleChange = (val: boolean) => {
  emit('update:visible', val);
};

// 处理消息类型变化
const handleMessageTypeChange = (val: MessageType) => {
  emit('update:activeMessageType', val);
};

// 监听 currentTask 变化，更新表单数据
watch(
  () => props.currentTask,
  (newTask) => {
    if (newTask.taskId) {
      // 如果是编辑或查看模式，确保表单数据与当前任务同步
      emit('update:editTaskForm', {
        ...props.editTaskForm,
        taskName: newTask.taskName || '',
        sendTimeType: newTask.sendTimeType || '1',
        sendTime: newTask.sendTime || '',
        selectedFriends: newTask.selectedFriends || [],
        selectedGroups: newTask.selectedGroups || []
      });
    }
  },
  { immediate: true, deep: true }
);

// 处理好友选择确认
const handleFriendSelectConfirm = (friends: Friend[]) => {
  emit('update:editTaskForm', {
    ...props.editTaskForm,
    selectedFriends: friends
  });
  selectFriendsDialogVisible.value = false;
};

// 处理群组选择确认
const handleGroupSelectConfirm = (groups: Group[]) => {
  emit('update:editTaskForm', {
    ...props.editTaskForm,
    selectedGroups: groups
  });
  selectGroupsDialogVisible.value = false;
};

// 处理移除好友
const handleRemoveFriend = (friend: Friend) => {
  const newFriends = props.editTaskForm.selectedFriends.filter((f) => f.wxId !== friend.wxId);
  emit('update:editTaskForm', {
    ...props.editTaskForm,
    selectedFriends: newFriends
  });
};

// 处理移除群组
const handleRemoveGroup = (group: Group) => {
  const newGroups = props.editTaskForm.selectedGroups.filter((g) => g.groupId !== group.groupId);
  emit('update:editTaskForm', {
    ...props.editTaskForm,
    selectedGroups: newGroups
  });
};

// 处理关闭
const handleClose = () => {
  emit('update:visible', false);
  emit('close');
};

// 处理提交
const handleSubmit = async () => {
  if (!formRef.value) return;

  try {
    await formRef.value.validate();
    if (props.messageList.length === 0) {
      ElMessage.warning('请添加消息内容');
      return;
    }
    emit('submit');
  } catch (error) {
    console.error('表单验证失败:', error);
  }
};

// 处理选择好友
const handleSelectFriends = () => {
  selectFriendsDialogVisible.value = true;
};

// 处理选择群组
const handleSelectGroups = () => {
  selectGroupsDialogVisible.value = true;
};

// 处理图片上传
const handleImageChange = (file: File) => {
  emit('image-change', file);
};

// 处理视频上传
const handleVideoChange = (file: File) => {
  emit('video-change', file);
};

// 处理移除图片
const handleRemoveImage = () => {
  emit('update:currentMessage', {
    ...props.currentMessage,
    data: {
      ...props.currentMessage.data,
      imageUrl: ''
    }
  });
};

// 处理预览图片
const handlePreviewImage = () => {
  if (props.currentMessage.data.imageUrl) {
    window.open(props.currentMessage.data.imageUrl, '_blank');
  }
};

// 处理添加消息
const handleAddMessage = () => {
  if (!props.currentMessage.data.content && props.activeMessageType === 'text') {
    ElMessage.warning('请输入文本内容');
    return;
  }
  if (!props.currentMessage.data.imageUrl && props.activeMessageType === 'image') {
    ElMessage.warning('请上传图片');
    return;
  }
  if (!props.currentMessage.data.videoUrl && props.activeMessageType === 'video') {
    ElMessage.warning('请上传视频');
    return;
  }
  if (!props.currentMessage.data.url && props.activeMessageType === 'link') {
    ElMessage.warning('请输入链接地址');
    return;
  }

  emit('add-message', props.currentMessage);
  emit('update:currentMessage', {
    type: 'text',
    data: {}
  });
};
</script>

<style lang="scss" scoped>
.task-dialog {
  :deep(.el-overlay) {
    .el-dialog {
      --el-dialog-margin-top: 5vh !important;
    }
  }

  :deep(.el-dialog__body) {
    padding: 0;
  }

  :deep(.el-dialog__header) {
    margin: 0;
    padding: 20px;
    border-bottom: 1px solid #ebeef5;
    background: #f5f7fa;
  }

  :deep(.el-dialog__title) {
    font-size: 18px;
    font-weight: 500;
    color: #303133;
  }

  :deep(.el-dialog__headerbtn) {
    top: 20px;
  }

  &-send {
    :deep(.el-form-item__content) {
      display: block;
    }
  }

  .task-form {
    padding: 0 24px;
    background: #fff;

    .el-form-item {
      margin-bottom: 10px;

      &:last-child {
        margin-bottom: 0;
      }

      :deep(.el-form-item__label) {
        font-weight: 500;
        color: #303133;
        padding-right: 16px;
      }

      :deep(.el-form-item__content) {
        .el-input__wrapper,
        .el-textarea__inner {
          box-shadow: 0 0 0 1px #dcdfe6 inset;
          transition: all 0.3s;

          &:hover {
            box-shadow: 0 0 0 1px #c0c4cc inset;
          }

          &:focus {
            box-shadow: 0 0 0 1px #409eff inset;
          }
        }
      }
    }

    .material-section {
      .material-options {
        display: flex;
        gap: 24px;
        align-items: center;

        .el-radio-group {
          display: flex;
          gap: 24px;

          :deep(.el-radio) {
            margin-right: 13px;
          }
        }

        .el-date-picker {
          width: 240px;
        }
      }
    }

    .target-section {
      .target-actions {
        margin-bottom: 10px;
        display: flex;
        gap: 12px;

        .el-button {
          padding: 8px 16px;
        }
      }

      .target-preview {
        background: #f5f7fa;
        padding: 10px 16px;
        border-radius: 8px;
        border: 1px solid #e4e7ed;
        margin: 10px 0;

        .target-group {
          margin-bottom: 16px;

          &:last-child {
            margin-bottom: 0;
          }

          .target-label {
            font-size: 14px;
            color: #606266;
            margin-bottom: 0px;
            font-weight: 500;
          }

          .target-list {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;

            .target-item {
              margin: 0;
              padding: 0 8px;
              height: 28px;
              line-height: 26px;
              border-radius: 4px;
              background: #fff;
              border: 1px solid #dcdfe6;
              color: #606266;
              transition: all 0.3s;

              &:hover {
                border-color: #409eff;
                color: #409eff;
              }

              .el-icon {
                margin-left: 4px;
                font-size: 12px;
              }
            }
          }
        }
      }
    }
  }

  .selectSend {
    margin: 0;
    border-radius: 0;
    box-shadow: none;
    padding: 0 24px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin-top: 24px;

    .section-title {
      font-size: 16px;
      font-weight: 500;
      color: #303133;
      margin-bottom: 20px;
      padding-left: 12px;
      border-left: 4px solid #409eff;
    }

    .message-tabs {
      :deep(.el-tabs__header) {
        margin-bottom: 24px;
      }

      :deep(.el-tabs__nav) {
        border: none;
      }

      :deep(.el-tabs__item) {
        height: 40px;
        line-height: 40px;
        font-size: 14px;
        color: #606266;
        padding: 0 20px;

        &.is-active {
          color: #409eff;
          font-weight: 500;
        }
      }

      .el-form-item {
        margin-bottom: 24px;

        &:last-child {
          margin-bottom: 0;
        }

        :deep(.el-form-item__label) {
          font-weight: 500;
          color: #303133;
        }
      }

      .image-uploader,
      .video-uploader {
        border: 1px dashed #d9d9d9;
        border-radius: 8px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
        width: 120px;
        height: 120px;
        display: flex;
        justify-content: center;
        align-items: center;
        transition: all 0.3s;

        &:hover {
          border-color: #409eff;
          background: #f5f7fa;
        }

        .upload-icon {
          font-size: 28px;
          color: #8c939d;
          transition: all 0.3s;
        }

        &:hover .upload-icon {
          color: #409eff;
        }

        .preview-image {
          width: 100%;
          height: 100%;
          object-fit: cover;
        }

        .preview-video {
          width: 100%;
          max-height: 178px;
        }
      }
    }

    .message-actions {
      margin-top: 10px;
      display: flex;
      justify-content: flex-end;
    }

    .message-preview-item-list {
      flex: 1;
      padding-right: 10px;
      padding: 10px;
      height: 90%;
      overflow: hidden;
      &::-webkit-scrollbar {
        width: 6px;
      }
      &::-webkit-scrollbar-thumb {
        background-color: #c0c4cc;
        border-radius: 3px;
      }
      &::-webkit-scrollbar-track {
        background-color: #f5f7fa;
      }
      .preview-title {
        font-size: 16px;
        font-weight: bold;
        margin-bottom: 10px;
        color: #303133;
      }
      .message-preview-item-list {
        overflow-y: auto;
        padding-right: 10px;
        padding: 10px;
        &::-webkit-scrollbar {
          width: 6px;
        }
        &::-webkit-scrollbar-thumb {
          background-color: #c0c4cc;
          border-radius: 3px;
        }
        &::-webkit-scrollbar-track {
          background-color: #f5f7fa;
        }
      }
      .message-preview-item {
        margin-bottom: 5px;
        transition: all 0.3s;
        border: 1px solid #ebeef5;
        border-radius: 8px;
        overflow: hidden;
        :deep(.el-card__body) {
          padding: 10px !important;
        }
        &:hover {
          transform: translateY(-2px);
          box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }

        .preview-header {
          display: flex;
          justify-content: space-between;
          align-items: flex-start;
          gap: 16px;

          .message-info {
            flex: 1;
            display: flex;
            align-items: flex-start;
            gap: 12px;

            .message-type-tag {
              padding: 4px 8px;
              border-radius: 4px;
              font-size: 12px;
              font-weight: 500;
              white-space: nowrap;
              flex-shrink: 0;

              &.text {
                background-color: #e6f7ff;
                color: #1890ff;
              }

              &.image {
                background-color: #f6ffed;
                color: #52c41a;
              }

              &.video {
                background-color: #fff7e6;
                color: #fa8c16;
              }

              &.link {
                background-color: #f9f0ff;
                color: #722ed1;
              }
            }

            .message-content {
              flex: 1;
              min-width: 0;
              font-size: 14px;
              color: #606266;
              word-break: break-all;
              white-space: pre-wrap;
              line-height: 2;
              .preview-image {
                max-width: 100px;
                max-height: 100px;
                border-radius: 8px;
                box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
              }
              .preview-video {
                max-width: 100px;
                max-height: 100px;
                border-radius: 8px;
                box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
              }
            }
          }

          .preview-actions {
            flex-shrink: 0;

            .action-buttons {
              display: flex;
              gap: 8px;
              align-items: center;

              .el-button {
                padding: 4px;

                &.is-disabled {
                  opacity: 0.5;
                  cursor: not-allowed;
                }

                .el-icon {
                  font-size: 16px;
                }
              }
            }
          }
        }
      }
    }
  }

  .dialog-footer {
    padding: 10px 24px;
    border-top: 1px solid #ebeef5;
    display: flex;
    justify-content: flex-end;
    gap: 12px;

    .el-button {
      padding: 8px 20px;
    }
  }
}

.right-content {
  width: 25%;
  background: #f6f8fa;
  border-radius: 30px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
  border: 1px solid #e5e7eb;
  padding: 10px;
  position: relative;
  &::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 40%;
    height: 20px;
    background: #e5e7eb;
    border-radius: 0 0 10px 10px;
  }

  .right-content-title {
    padding: 20px;
    font-size: 18px;
    font-weight: 600;
    color: #1f2937;
    border-bottom: 1px solid #e5e7eb;
    background: #ffffff;
  }

  .right-content-preview {
    flex: 1;
    overflow: hidden;
    height: calc(100vh - 400px);

    .wechat-preview {
      background: #ffffff;
      border-radius: 12px;
      height: 100%;
      display: flex;
      flex-direction: column;
      box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
      border: 1px solid #eef2f6;

      .wechat-header {
        padding: 16px;
        background: linear-gradient(to right, #f8fafc, #ffffff);
        border-bottom: 1px solid #eef2f6;
        text-align: center;

        .wechat-title {
          font-size: 17px;
          font-weight: 600;
          color: #2c3e50;
          letter-spacing: 0.5px;
        }
      }

      .wechat-messages {
        flex: 1;
        padding: 20px;
        overflow-y: auto;
        background: #f6f8fa;
        background-image: linear-gradient(rgba(0, 0, 0, 0.02) 1px, transparent 1px), linear-gradient(90deg, rgba(0, 0, 0, 0.02) 1px, transparent 1px);
        background-size: 20px 20px;

        .message-item {
          display: flex;
          margin-bottom: 20px;
          align-items: flex-start;
          animation: fadeIn 0.3s ease-in-out;

          @keyframes fadeIn {
            from {
              opacity: 0;
              transform: translateY(10px);
            }
            to {
              opacity: 1;
              transform: translateY(0);
            }
          }

          .message-avatar {
            width: 44px;
            height: 44px;
            border-radius: 8px;
            overflow: hidden;
            margin-right: 12px;
            flex-shrink: 0;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
            border: 2px solid #ffffff;

            img {
              width: 100%;
              height: 100%;
              object-fit: cover;
            }
          }

          .message-content {
            max-width: 70%;

            .message-bubble {
              background: #ffffff;
              padding: 14px;
              border-radius: 12px;
              box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
              word-break: break-all;
              position: relative;
              border: 1px solid #eef2f6;

              &::before {
                content: '';
                position: absolute;
                left: -8px;
                top: 14px;
                width: 16px;
                height: 16px;
                background: #ffffff;
                transform: rotate(45deg);
                border-left: 1px solid #eef2f6;
                border-bottom: 1px solid #eef2f6;
              }

              .preview-image {
                border-radius: 8px;
                box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
              }

              .preview-video {
                border-radius: 8px;
                box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
              }

              .link-preview {
                background: #f8fafc;
                border-radius: 8px;
                padding: 12px;
                border: 1px solid #eef2f6;

                .link-title {
                  font-weight: 600;
                  color: #2c3e50;
                  margin-bottom: 6px;
                  font-size: 15px;
                }

                .link-url {
                  color: #3b82f6;
                  font-size: 13px;
                  margin-bottom: 6px;
                  word-break: break-all;
                }

                .link-desc {
                  color: #64748b;
                  font-size: 13px;
                  line-height: 1.5;
                }
              }
            }
          }
        }
      }
    }
  }
}

.image-uploader {
  width: 100px;
  height: 100px;
  border: 1px dashed #d9d9d9;
  border-radius: 8px;
  cursor: pointer;
  position: relative;
  transition: all 0.3s;

  &:hover {
    border-color: #409eff;
    background: #f5f7fa;
  }

  .upload-icon {
    font-size: 28px;
    color: #8c939d;
    transition: all 0.3s;
  }

  &:hover .upload-icon {
    color: #409eff;
  }

  .preview-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}

:deep(.el-upload--picture-card) {
  width: 100px;
  height: 100px;
  line-height: 100px;
}

:deep(.el-upload-list--picture-card .el-upload-list__item) {
  width: 100px;
  height: 100px;
}

:deep(.el-overlay) {
  .task-dialog {
    --el-dialog-margin-top: 1vh !important;
  }
}

.target-item {
  &.is-disabled {
    background-color: #f5f7fa;
    border-color: #e4e7ed;
    color: #c0c4cc;
    cursor: not-allowed;

    &:hover {
      border-color: #e4e7ed;
      color: #c0c4cc;
    }
  }
}
</style>
